package dahuiji.common.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import dahuiji.common.util.Constants;

public class CheckVerifycode extends BaceServlet {

	/**
	 * Constructor of the object.
	 */
	public CheckVerifycode() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * Initialization of the servlet. <br>
	 * 
	 * @throws ServletException
	 *             if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

	@Override
	public String perform(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String codeinput = request.getParameter("code");
		HttpSession session = request.getSession();
		String code = (String) session.getAttribute("verifycode");
		if (codeinput != null || !codeinput.equals("")) {
			if (code != null || !code.equals("")) {
				if (code.equals(codeinput)) {
					response.getWriter()
							.print(Constants.VERIFYCODE_INPUT_RIGTH);

				} else {
					response.getWriter()
							.print(Constants.VERIFYCODE_INPUT_WRONG);

				}
			}
		}

		return null;
	}

}
